import Vue from 'vue';
import Vuex from 'vuex';
import Storage from '@/global/storage';

Vue.use(Vuex);

export default new Vuex.Store({
    namespaced: true,
    state: {
        collapse: false,
        tabList: Storage.get("tabs") || [{ title: '数据中心', path: '/home' }],
        userInfo: {},
    },
    mutations: {
        updateCollapseStatus(state, status) {
            if (status == null) {
                state.collapse = !state.collapse;
            } else {
                state.collapse = status;
            }
        },
        addTabs(state, tabs) {
            let status = state.tabList.some(data => data.path === tabs.path);

            if (!status) {
                state.tabList.push({
                    title: tabs.name,
                    path: tabs.path
                })
            }

            Storage.set("tabs", state.tabList);
        },
        getUserInfo(state, userInfo) {
            state.userInfo = userInfo.data;
        },
        removeCompleted(state, tabs) {
            if (state.tabList.length > 1) {
                state.tabList.splice(tabs.index, 1)
            }

            Storage.set("tabs", state.tabList)
        }
    },
    actions: {
    },
    modules: {
    }
});
